let preset_themes = [
  {
    value: "primary",
    text: "主题",
  },
  {
    value: "error",
    text: "错误",
  },
  {
    value: "success",
    text: "成功",
  },
  {
    value: "default",
    text: "默认",
  },
]

let switch_btn = document.querySelector('.switch')
// 是否开启
let check = false
// 当前的主题
let cur_themes = 0
// 是否禁用
let disable = true
switch_btn.addEventListener('click',function(){
  if(disable){
    return
  }

  check = !check
  if(check){
    switch_btn.classList.add(`${preset_themes[cur_themes].value}_active`)
    switch_btn.classList.add(`active`)
  }else{
    switch_btn.className = 'switch'
  }
})

disable && switch_btn.classList.add('disable')

let themes_list = document.querySelector('.themes_list')

function createdThemesOption(){
  preset_themes.forEach((item,index)=>{
    let themes_item = document.createElement('div')
    themes_item.classList.add('themes_item')
    let span = document.createElement('span')
    span.innerText = item.text
    themes_item.appendChild(span)
    let input = document.createElement('input')
    input.classList.add('input_radio')
    input.type = 'radio'
    input.value = item.value
    if(index == 0){
      input.checked = true
    }
    themes_item.appendChild(input)
    themes_list.appendChild(themes_item)

    themes_item.addEventListener('click',function(){
      let input_list = document.querySelectorAll('.input_radio')
      input_list.forEach(item=>{
        item.checked = false
      })
      if(check){
        switch_btn.className = `switch ${input.value}_active active`
        if(disable){
          switch_btn.classList.add('disable')
        }
      }
      input.checked = !input.checked
      cur_themes = index
      console.log(index,"kkk");
    })
  })
}

createdThemesOption()

let disable_input_list = document.querySelectorAll('.disable_input')

function disableChange(e){
  disable = !disable
  if(disable){
    switch_btn.classList.add('disable')
  }else{
    switch_btn.classList.remove('disable')

  }
  disable_input_list.forEach(el=>{
    el.checked = false
  })
  e.checked = true

}
